﻿using System;

namespace MPMovieCatalog.Domain
{
    [Serializable()]
    public abstract class NamedEntity
    {
        public static int CompareByName(NamedEntity entity1, NamedEntity entity2)
        {
            if (entity1 == null)
            {
                if (entity2 == null)
                {
                    return 0;
                }
                else
                {
                    return -1;
                }
            }
            else
            {
                if (entity2 == null)
                {
                    return 1;
                }
                else
                {
                    return CompareStrings(entity1.Name, entity2.Name);
                }
            }
        }

        private static int CompareStrings(string s1, string s2)
        {
            if (s1 == null)
            {
                if (s2 == null)
                {
                    return 0;
                }
                else
                {
                    return -1;
                }
            }
            else
            {
                if (s2 == null)
                {
                    return 1;
                }
                else
                {
                    return s1.CompareTo(s2);
                }
            }
        }

        public override string ToString()
        {
            return Name;
        }

        public long Id { get; set; }

        public string Name { get; set; }
    }
}
